//
// Created by kai-xu on 2022/12/16.
//

#ifndef PRO_MAT_INCLUDE_PRO_MAT_UTILS_H_
#define PRO_MAT_INCLUDE_PRO_MAT_UTILS_H_

#endif  // PRO_MAT_INCLUDE_PRO_MAT_UTILS_H_

#include <cuda_fp16.h>
#include <cuda_runtime.h>

#include <iostream>
#include <vector>

#define checkKernelErrors(expr)                             \
  do {                                                      \
    expr;                                                   \
                                                            \
    cudaError_t __err = cudaGetLastError();                 \
    if (__err != cudaSuccess) {                             \
      printf("Line %d: '%s' failed: %s\n", __LINE__, #expr, \
             cudaGetErrorString(__err));                    \
      abort();                                              \
    }                                                       \
  } while (0)

#define CHECK(status)         \
  do {                        \
    if (status != 0) abort(); \
  } while (0)

namespace circle_ray {

struct custom_coor_point {
  int32_t x;
  int32_t y;
  int32_t z;
  float xf;
  float yf;
  float zf;
};
extern "C" {
int32_t cal_coor_gpu(custom_coor_point* coor_value, float* aug_mat,
                     float* ego_mat, int32_t sd_x, int32_t sd_y, int32_t n_cam,
                     int32_t dz, int32_t width, int32_t height,
                     std::vector<float> voxel_size,
                     std::vector<float> coors_range);

int32_t coor_reduce_hdim(custom_coor_point* o_coor_value,
                         custom_coor_point* i_coor_value, int32_t bs,
                         int32_t nc, int32_t dz, int32_t height, int32_t width);

int32_t coor_permute(custom_coor_point* o_coor_value,
                     custom_coor_point* i_coor_value, int32_t* idx_ptr,
                     int32_t bs, int32_t nc, int32_t dz, int32_t width,
                     int32_t out_height, int32_t out_width);

int32_t coor_map(float* circle_map, float* ray_map, const int32_t* idx_ptr,
                 int32_t bs, int32_t nc, int32_t dz, int32_t width,
                 int32_t out_height, int32_t out_width);
}
}  // namespace circle_ray
